/** @file QTCtoolbarbutton.qml
@brief The Qt-Complex Dynamic toolbar button definition

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0
import "Tools.js" as QTCtools

BorderImage {
    id: qtc_toolbar_button

    signal objClicked

    visible: objGroupLoad.getEnabled() == true ? true : false
    source: objGroupLoad.getButton()
    border { left: 1; top: 1; right: 1; bottom: 1 }

    width: objGroupLoad.getWidth()
    height: objGroupLoad.getHeight()

    // Icon image over the button
    Image {
        id: qtc_buttonicon

        visible: objGroupLoad.getEnabled() == true ? true : false
        fillMode: Image.PreserveAspectFit
        width: Math.round(parent.width * QTCtools.tb_iconSize)
        height: Math.round(parent.height * QTCtools.tb_iconSize)
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        source: objGroupLoad.getIcon()
    }

    // Shade is set over the button image when it is presed
    Rectangle {
        id: shade;
        visible: objGroupLoad.getEnabled() == true ? true : false
        anchors.fill: qtc_toolbar_button; radius: 50; color: "black"; opacity: 0
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: if (objGroupLoad.getEnabled() == true)
                       qtc_toolbar_button.objClicked();
    }

    // When button is pressed the shade changes
    states: State {
        name: "pressed"; when: (mouseArea.pressed == true) && (objGroupLoad.getEnabled() == true)
        PropertyChanges { target: shade; opacity: .2 }
    }
}
